package com.io;

import java.io.IOException;
import java.io.RandomAccessFile;

public class RandomFile {

	static String filepath = RandomFile.class.getClassLoader().getResource("write.txt").getFile();

	static void randomOpe() throws IOException {
		RandomAccessFile file = null;
		try {
			file = new RandomAccessFile(filepath, "rw");
			file.seek(0);
			file.write('1');

			file.seek(0);
			System.out.println(file.read());

			// 读取
			int data = -1;
			while ((data = file.read()) != -1) {// -1 表示读取到达文件结尾
				// 操作数据
				System.out.print((byte) data + " ");
			}
		} finally {

			file.close();
		}

	}

	public static void main(String[] args) throws IOException {
		randomOpe();
	}

}
